package com.ruanjian.api.utils;

/**
 * @author shkstart
 * @create 2022-11-20 13:34
 */
public class RandomUtil {

    /**
     * 0.65出现的概率为1/3
     */
    private static double rate0 = (double) 1/3;
    /**
     * 0.5出现的概率为1/3
     */
    private static double rate1 = (double) 1/3;
    /**
     * 0.35出现的概率为1/3
     */
    private static double rate2 = (double) 1/3;

    public RandomUtil() {
    }

    public RandomUtil(double rate0, double rate1, double rate2) {
        this.rate0 = rate0;
        this.rate1 = rate1;
        this.rate2 = rate2;
    }

    public double getRate0() {
        return rate0;
    }

    public void setRate0(double rate0) {
        this.rate0 = rate0;
    }

    public double getRate1() {
        return rate1;
    }

    public void setRate1(double rate1) {
        this.rate1 = rate1;
    }

    public double getRate2() {
        return rate2;
    }

    public void setRate2(double rate2) {
        this.rate2 = rate2;
    }

    /**
     * 本轮上升、下降情况
     *  0: 下降
     *  1: 上升
     *  -1: 未知
     */
    public static int isIncry(double j){
        double randomNumber;
        randomNumber = Math.random();

        if (randomNumber >= 0 && randomNumber <= j)
            return 1;
        else if (randomNumber > j && randomNumber <= 1)
            return 0;

        return -1;

    }

    /**
     * Math.random()产生一个double型的随机数，判断一下
     * <p>
     * 例如0.65出现的概率为1/3，则介于0到1/3中间的返回
     *
     * @return int
     */
    public static double PercentageRandom() {
        double randomNumber;
        randomNumber = Math.random();

        if (randomNumber >= 0 && randomNumber <= rate0) {

            return 0.65;

        } else if (randomNumber > rate0 && randomNumber <= rate0 + rate1) {

            return 0.5;

        } else if (randomNumber > rate0 + rate1

                && randomNumber <= rate0 + rate1 + rate2) {

            return 0.35;

        }
        return -1;

    }

}
